package com.ptr.ptrsystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ptr.ptrsystem.logica.*;

/**
 *
 * @author WALDIR
 */
@WebServlet(name = "MantenimientoDefuncionServlet", urlPatterns = {"/MantenimientoDefuncion"})
public class MantenimientoDefuncionServlet extends HttpServlet {

    public MantenimientoDefuncionServlet() {
    }

    String NRO_ACT_PER;
    String NRO_ACTA_CDEF;
    String FECH_REG_DEF;
    String IDUBIGEO;
    String COD_LUG_OCC;
    String FECH_DEF;
    String HOR_DEF;
    String DNI_M;
    String DNI_P;
    String DNI_DECL;
    String DNI_PER_REG;
    String COD_ESTADO;
    String COD_T_DOC;
    String OBS;
    String RUT_ACT_DEF;
        
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        NRO_ACT_PER=request.getParameter("NAPers").trim();
        NRO_ACTA_CDEF=request.getParameter("NACDEF").trim();
        FECH_REG_DEF=request.getParameter("FechRegDef").trim();
        IDUBIGEO=request.getParameter("IdUbigeo").trim();
        COD_LUG_OCC=request.getParameter("CodLugOcurr").trim();
        FECH_DEF=request.getParameter("FecDef").trim();
        HOR_DEF=request.getParameter("HorDef").trim();
        DNI_M=request.getParameter("DNIMadre").trim();
        DNI_P=request.getParameter("DNIPadre").trim();
        DNI_DECL=request.getParameter("DNIDecl").trim();
        DNI_PER_REG=request.getParameter("DNIPerReg").trim();
        COD_ESTADO=request.getParameter("CodEst");
        COD_T_DOC=request.getParameter("CodTDoc");
        OBS=request.getParameter("Obs");
        RUT_ACT_DEF=request.getParameter("RutActDef");
        String BTN=request.getParameter("btn1");
        if(BTN.equals("guardaDef"))
        {
            GuardarDefuncion(request, response);
        }
   
    }
    protected void GuardarDefuncion(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        LogicaDefuncion Defun=new LogicaDefuncion();
        boolean DF=Defun.insertarDefuncion(NRO_ACT_PER, NRO_ACTA_CDEF, FECH_REG_DEF, IDUBIGEO, COD_LUG_OCC, FECH_DEF, HOR_DEF, DNI_M, DNI_P, DNI_DECL, DNI_PER_REG, COD_ESTADO, COD_T_DOC, NRO_ACT_PER, RUT_ACT_DEF);
        if (DF) {
            request.setAttribute("msj","2");
            request.getRequestDispatcher("/jsp/NDefuncion.jsp").forward(request, response);  
        } else {
             request.setAttribute("msj","1");
            request.getRequestDispatcher("/jsp/NDefuncion.jsp").forward(request, response);  
        }
   
    }
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
